import { Module } from '@nestjs/common';
import { UserClientController } from './user-client.controller';
import { UserClientService } from './user-client.service';
import { CacheModule } from '@app/cache';
import { UserModule } from './user/user.module';
import { LoginModule } from './login/login.module';
import { ConfigureModule, ConfigureService } from '@app/configure';
import { JwtVerifyModule } from '@app/jwt-verify';
import { UtilsModule } from '@app/utils';
import { TypeOrmModule } from '@nestjs/typeorm';
import { BaseModule } from '@app/db/base/base.module';
import { APP_GUARD } from '@nestjs/core';
import { AuthGuard } from './guard/auth/auth.guard';
import { ChargeModule } from './charge/charge.module';
import { ChargeOrderModule } from './charge-order/charge-order.module';
import { DeviceModule } from './device/device.module';
import { WalletLogModule } from './wallet-log/wallet-log.module';
import { CommonModule } from './common/common.module';
import { WechatModule } from './wechat/wechat.module';
import { MongooseModule } from '@nestjs/mongoose';
import { RechargeModule } from './recharge/recharge.module';
import { PaymentModule } from './payment/payment.module';
import { PrivateDeviceModule } from './private-device/private-device.module';
import { ChargingStationModule } from './charging-station/charging-station.module';
import { ChargingCardModule } from './charging-card/charging-card.module';
import { AlipayModule } from './alipay/alipay.module';

@Module({
  imports: [
    TypeOrmModule.forRootAsync({
      name : 'common',
      imports : [ConfigureModule],
      inject : [ConfigureService],
      useFactory : (config:ConfigureService) => {
        return {
          ...config.get('database.common'),
        }
      },

      // dataSourceFactory: async (options) => {
      //   const dataSource = await new DataSource(options).initialize();
      //   return dataSource;
      // },
    }),


    TypeOrmModule.forRootAsync({
      imports : [ConfigureModule],
      inject : [ConfigureService],
      useFactory : (config:ConfigureService) => {
        return {
          ...config.get('database.default'),
        }
      },

      // dataSourceFactory: async (options) => {
      //   const dataSource = await new DataSource(options).initialize();
      //   return dataSource;
      // },
    }),

    MongooseModule.forRootAsync({
      imports : [ConfigureModule],
      inject : [ConfigureService],
      useFactory : (config:ConfigureService) => {
        return {
          ...config.get('mongodb'),
        }
      }
    }),


    BaseModule,


    CacheModule,
    UtilsModule,
    JwtVerifyModule,
    ConfigureModule,
    
    UserModule,
    LoginModule,
    ChargeModule,
    ChargeOrderModule,
    DeviceModule,
    WalletLogModule,
    CommonModule,
    WechatModule,
    RechargeModule,
    PaymentModule,
    PrivateDeviceModule,
    ChargingStationModule,
    ChargingCardModule,
    AlipayModule
  ],
  controllers: [UserClientController],
  providers: [UserClientService, {provide : APP_GUARD, useClass : AuthGuard}],
})
export class UserClientModule {}
